home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / misc / PowerUp.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.6 KB  |  126 lines

  1. class classes.misc.PowerUp
  2. {
  3.    var x;
  4.    var y;
  5.    var type;
  6.    var id;
  7.    var clip;
  8.    var xMov;
  9.    var yMov;
  10.    var f2 = "checkHit";
  11.    var c = 0;
  12.    var yank = false;
  13.    var weapon = false;
  14.    var Name = "powerUp";
  15.    function PowerUp(px, py, ptype, pid)
  16.    {
  17.       this.x = px;
  18.       this.y = py;
  19.       this.type = ptype;
  20.       this.id = pid;
  21.       _root.d = _root.d + 1;
  22.       this.clip = _root.attachMovie("powerUp","powerUp" + this.id + "Clip",_root.d);
  23.       this.clip._x = this.x;
  24.       this.clip._y = this.y;
  25.       this.clip.gotoAndStop(this.type);
  26.       var _loc3_ = _root.getAngleRad2(this.x,this.y,500,300);
  27.       this.xMov = Math.cos(_loc3_) * _root.randRange2(0.5,2.5);
  28.       this.yMov = Math.sin(_loc3_) * _root.randRange2(0.5,2.5);
  29.       if(this.type == "doubleLaserA" || this.type == "tripleLaserA" || this.type == "twistLaser" || this.type == "tripleTwistLaser" || this.type == "rapidLaser" || this.type == "bigLaser")
  30.       {
  31.          this.weapon = true;
  32.       }
  33.    }
  34.    function hit()
  35.    {
  36.       if(this.weapon)
  37.       {
  38.          _root.audio.playLevel3("weaponUpgrade",25);
  39.       }
  40.       else if(this.type.charAt(0) == "g")
  41.       {
  42.          _root.audio.playLevel3("gem" + (random(3) + 1),_root.randRange(20,30));
  43.       }
  44.       else if(this.type.substr(0,10) == "speedBoost")
  45.       {
  46.          _root.audio.playLevel3("speedBoost",_root.randRange(29,35));
  47.       }
  48.       else if(this.type.substr(0,11) == "weaponBoost")
  49.       {
  50.          _root.audio.playLevel3("weaponBoost",_root.randRange(29,35));
  51.       }
  52.       else if(this.type.substr(0,6) == "shield")
  53.       {
  54.          _root.audio.playLevel3("shield2",_root.randRange(29,35));
  55.       }
  56.       else
  57.       {
  58.          _root.audio.playLevel3(this.type,_root.randRange(29,35));
  59.       }
  60.       this.clip[this.type].gotoAndPlay("hit");
  61.       this.f2 = "ending";
  62.    }
  63.    function ending()
  64.    {
  65.       if(this.clip.end)
  66.       {
  67.          this.yank = true;
  68.       }
  69.    }
  70.    function checkHit()
  71.    {
  72.       if(this.weapon)
  73.       {
  74.          if(this.clip[this.type].hitClip.hitTest(_root[_root.char + "Clip"]))
  75.          {
  76.             _root[_root.char].powerUp(this.type);
  77.             this.hit();
  78.          }
  79.       }
  80.       else if(this.clip.hitTest(_root[_root.char + "Clip"]))
  81.       {
  82.          _root[_root.char].powerUp(this.type);
  83.          this.hit();
  84.       }
  85.    }
  86.    function main()
  87.    {
  88.       this.c = this.c + 1;
  89.       this[this.f2]();
  90.       if(this.c > 30 && this.type == "smartBomb")
  91.       {
  92.          var _loc4_ = 0;
  93.          var _loc6_ = _root.broShots.length;
  94.          while(_loc4_ < _loc6_)
  95.          {
  96.             var _loc5_ = _root.broShots[_loc4_] + "Clip";
  97.             if(this.clip.hitTest(_root[_loc5_]))
  98.             {
  99.                var _loc3_ = _root.broShots[_loc4_];
  100.                this.xMov += _root[_loc3_].xMov / 20;
  101.                this.yMov += _root[_loc3_].yMov / 20;
  102.                _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  103.                _root[_loc3_].exploX = this.x + this.clip._width / 2;
  104.                _root[_loc3_].exploY = this.y + this.clip._height / 2;
  105.                _root[_loc3_].hit();
  106.                _root[_root.char].powerUp(this.type);
  107.                this.hit();
  108.             }
  109.             _loc4_ = _loc4_ + 1;
  110.          }
  111.       }
  112.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  113.       {
  114.          this.yank = true;
  115.       }
  116.       if(this.yank)
  117.       {
  118.          _root.removePowerUp("powerUp" + this.id);
  119.       }
  120.       this.x += this.xMov;
  121.       this.y += this.yMov;
  122.       this.clip._x = this.x;
  123.       this.clip._y = this.y;
  124.    }
  125. }
  126.